import { createApp } from "vue";
import naive from "naive-ui";
import TDesign from "tdesign-mobile-vue";
import App from "./App.vue";
import router from "./router"; // 引入路由实例
import useCookies from "vue3-cookies";
// 引入组件库的少量全局样式变量
import "tdesign-mobile-vue/es/style/index.css";
import { registerSW } from "virtual:pwa-register";
import waterfall from "vue-waterfall2";
console.log("registerSW 是否存在：", typeof registerSW);

// 注册 Service Worker
if ("serviceWorker" in navigator) {
  window.addEventListener("load", () => {
    // 开发环境 SW 路径通常为 /dev-sw.js?dev-sw
    const swUrl = import.meta.env.DEV ? "/dev-sw.js?dev-sw" : "/sw.js";

    navigator.serviceWorker
      .register(swUrl)
      .then((registration) => {})
      .catch((error) => {
        console.error("手动注册失败：", error);
      });
  });
} else {
  console.warn("浏览器不支持 Service Worker");
}

createApp(App)
  .use(router) // 注册路由
  .use(naive)
  .use(TDesign)
  .use(useCookies)
  .use(waterfall)
  .mount("#app");
